import unittest, requests

class MyTestCase(unittest.TestCase):
    host = 'http://10.59.9.18'
    # 登陆
    userId = None
    sessionId = None
    status=None
    def test_01_login(self):
        url = MyTestCase.host + '/small/user/v1/login'
        json = {"phone": "15535738398", "pwd": "zjj031613"}
        r = requests.post(url=url, json=json)
        print(r.json())
        MyTestCase.userId = str(r.json()['result']['userId'])
        MyTestCase.sessionId = r.json()['result']['sessionId']
        MyTestCase.status = r.json()['status']
    # 首页商品信息列表
    commodityId = None

    def test_02_commodityList(self):
        url = MyTestCase.host + '/small/commodity/v1/commodityList'
        r = requests.get(url=url)
        print(r.json())
        MyTestCase.commodityId = r.json()['result']['rxxp']['commodityList'][0]['commodityId']

    # 商品详情
    def test_03_findCommodityDetailsById(self):
        url = MyTestCase.host + '/small/commodity/v1/findCommodityDetailsById'
        json = {"commodityId": MyTestCase.commodityId}
        r = requests.get(url=url, data=json)
        print(r.json())

    # 修改昵称
    def test_04_findCommodityDetailsById(self):
        url = MyTestCase.host + '/small/user/verify/v1/modifyUserNick'
        headers = {"userId": MyTestCase.userId, "sessionId": MyTestCase.sessionId}
        json = {"nickName": "顶顶顶"}
        r = requests.put(url=url, data=json, headers=headers)
        print(r.json())

    # 修改用户密码
    def test_05_modifyUserPwd(self):
        url = MyTestCase.host + '/small/user/verify/v1/modifyUserPwd'
        headers = {"userId": MyTestCase.userId, "sessionId": MyTestCase.sessionId}
        json = {"oldPwd": "123", "newPwd": "123"}
        r = requests.put(url=url, data=json, headers=headers)
        print(r.json())

    # 根据用户ID查询用户信息
    def test_06_getUserById(self):
        url = MyTestCase.host + '/small/user/verify/v1/getUserById'
        headers = {"userId": MyTestCase.userId, "sessionId": MyTestCase.sessionId}
        r = requests.get(url=url, headers=headers)
        print(r.json())

    # 新增收货地址
    def test_07_addReceiveAddress(self):
        url = MyTestCase.host + '/small/user/verify/v1/addReceiveAddress'
        headers = {"userId": MyTestCase.userId, "sessionId": MyTestCase.sessionId}
        json = {"realName": "张三", "phone": '13836479527', "address": "北京 海淀区 八维", "zipCode": "100000"}
        r = requests.post(url=url, headers=headers, data=json)
        print(r.json())

    # 收货地址列表
    def test_08_receiveAddressList(self):
        url = MyTestCase.host + '/small/user/verify/v1/receiveAddressList'
        headers = {"userId": MyTestCase.userId, "sessionId": MyTestCase.sessionId}
        r = requests.get(url=url, headers=headers)
        print(r.json())

    # 设置默认收货地址
    def test_09_setDefaultReceiveAddress(self):
        url = MyTestCase.host + '/small/user/verify/v1/setDefaultReceiveAddress'
        headers = {"userId": MyTestCase.userId, "sessionId": MyTestCase.sessionId}
        json = {"id": 8902}
        r = requests.post(url=url, data=json, headers=headers)
        print(r.json())

    # 修改收货信息
    def test_10_changeReceiveAddress(self):
        url = MyTestCase.host + '/small/user/verify/v1/changeReceiveAddress'
        headers = {"userId": MyTestCase.userId, "sessionId": MyTestCase.sessionId}
        json = {"realName": "李四", "phone": '13836479527', "address": "北京 海淀区 八维", "zipCode": "100000"}
        r = requests.put(url=url, headers=headers, params=json)
        print(r.json())

    # 查询用户钱包
    def test_11_findUserWallet(self):
        url = MyTestCase.host + '/small/user/verify/v1/findUserWallet'
        headers = {"userId": MyTestCase.userId, "sessionId": MyTestCase.sessionId}
        json = {"page": 1, "count": 1}
        r = requests.get(url=url, headers=headers, params=json)
        print(r.json())

    #删除收货地址
    @unittest.skip
    def test_12_deleteReceiveAddress(self):
        url = MyTestCase.host + '/small/user/verify/v1/deleteReceiveAddress'
        headers = {"userId": MyTestCase.userId, "sessionId": MyTestCase.sessionId}
        json = {"id": 8902}
        r = requests.delete(url=url, headers=headers, data=json)
        print(r.json())

    #查询app最新版本信息
    def test_13_findAppVersion(self):
        url = MyTestCase.host + '/small/user/v1/findAppVersion'
        json = {"appVersionNum": 1}
        r = requests.get(url=url,params=json)
        print(r.json())

    #创建订单
    def test_14_createOrder(self):
        url = MyTestCase.host + '/small/order/verify/v1/createOrder'
        headers = {"userId": MyTestCase.userId, "sessionId": MyTestCase.sessionId}
        json = {"orderInfo":[{"commodityId":3,"amount":1}],"totalPrice":"520.55","addressId":"8902"}
        r = requests.post(url=url,params=json,headers=headers)
        print(r.json())

    #根据订单状态查询订单信息
    def test_15_findOrderListByStatus(self):
        url = MyTestCase.host + '/small/order/verify/v1/findOrderListByStatus'
        headers = {"userId": MyTestCase.userId, "sessionId": MyTestCase.sessionId}
        json ={"status":MyTestCase.status,"page":1,"count":5}
        r = requests.get(url=url,params=json,headers=headers)
        print(r.json())

    #删除订单
    def test_16_deleteOrder(self):
        url = MyTestCase.host + '/small/order/verify/v1/deleteOrder'
        headers = {"userId": MyTestCase.userId, "sessionId": MyTestCase.sessionId}
        json = {"orderId":"2018112211424963613"}
        r = requests.delete(url=url, params=json, headers=headers)
        print(r.json())

    #查询购物车
    def test_17_findShoppingCart(self):
        url = MyTestCase.host + '/small/order/verify/v1/findShoppingCart'
        headers = {"userId": MyTestCase.userId, "sessionId": MyTestCase.sessionId}
        r = requests.get(url=url, headers=headers)
        print(r.json())

    #查询订单明细数据 /small/order/verify/v1/findOrderInfo
    def test_18_findOrderInfo(self):
        url = MyTestCase.host + '/small/order/verify/v1/findOrderInfo'
        headers = {"userId": MyTestCase.userId}
        json={"orderId":"2018112211424963613"}
        r = requests.get(url=url,data=json,headers=headers)
        print(r.json())
    #圈子列表
    def test_19_findCircleList(self):
        url = MyTestCase.host + '/small/circle/v1/findCircleList'
        headers = {"userId": MyTestCase.userId, "sessionId": MyTestCase.sessionId}
        json={"page":1,"count":5}
        r = requests.get(url=url,params=json,headers=headers)
        print(r.json())
    #我的圈子
    def test_20_findMyCircleById(self):
        url = MyTestCase.host + '/small/circle/verify/v1/findMyCircleById'
        headers = {"userId": MyTestCase.userId, "sessionId": MyTestCase.sessionId}
        json = {"page": 1, "count": 5}
        r = requests.get(url=url, params=json, headers=headers)
        print(r.json())
    #banner展示列表
    def test_21_bannerShow(self):
        url = MyTestCase.host + '/small/commodity/v1/bannerShow'
        r = requests.get(url=url)
        print(r.json())
    #根据商品列表归属标签查询商品信息
    def test_22_findMyCircleById(self):
        url = MyTestCase.host + '/small/circle/verify/v1/findMyCircleById'
        headers = {"userId": MyTestCase.userId, "sessionId": MyTestCase.sessionId}
        json={"labelId":1010,"page":1,"count":5}
        r = requests.get(url=url,params=json,headers=headers)
        print(r.json())
    #根据关键词查询商品信息
    def test_23_findMyCircleById(self):
        url = MyTestCase.host + '/small/circle/verify/v1/findMyCircleById'
        headers = {"userId": MyTestCase.userId, "sessionId": MyTestCase.sessionId}
        json={"labelId":"裤子","page":1,"count":5}
        r = requests.get(url=url,params=json,headers=headers)
        print(r.json())

    #根据二级类目查询商品信息
    def test_24_findCommodityByCategory(self):
        url = MyTestCase.host + '/small/commodity/v1/findCommodityByCategory'
        headers = {"userId": MyTestCase.userId, "sessionId": MyTestCase.sessionId}
        json={"categoryId":1001004002,"page":1,"count":5}
        r = requests.get(url=url,params=json,headers=headers)
        print(r.json())
    #我的足迹
    def test_25_browseList(self):
        url = MyTestCase.host + '/small/commodity/verify/v1/browseList'
        headers = {"userId": MyTestCase.userId, "sessionId": MyTestCase.sessionId}
        json={"page":1,"count":5}
        r = requests.get(url=url,params=json,headers=headers)
        print(r.json())
    #查询商品类目
    def test_26_findCategory(self):
        url = MyTestCase.host + '/small/commodity/v1/findCategory'
        r = requests.get(url=url)
        print(r.json())
    #查询推荐商品
    def test_27_findRecommendCommodity(self):
        url = MyTestCase.host + '/small/commodity/v1/findRecommendCommodity'
        r = requests.get(url=url)
        print(r.json())
    #查询商品库存数量
    def test_28_getInventory(self):
        url = MyTestCase.host + '/small/commodity/v1/getInventory'
        json={"commodityId":MyTestCase.commodityId}
        r = requests.get(url=url,data=json)
        print(r.json())

#执行
if __name__ == '__main__':
    unittest.main()
